/**
 *
 * @param obj
 * @param reset 移除字段数组集合
 * @returns 返回一个新的对象
 */
export const omit = (
  obj: Record<string, any>,
  ...reset: string[]
): Record<string, any> | never => {
  if (typeof obj !== 'object') {
    return new Error('你传入的不是一个对象值')
  }
  const result: Record<string, any> = {}
  Object.keys(obj).forEach(key => {
    if (!reset.includes(key)) {
      result[key] = obj[key]
    }
  })
  return result
}
/*
  example
  const obj = { a: 1, b: 2, c: 3 }
  const newObj = omit(obj, 'a', 'b')
  console.log(newObj) // {c: 3}
*/

/**
 *
 * @param obj
 * @param reset 筛选的字段数组集合
 * @returns 返回一个新的对象
 */
export const pick = (
  obj: Pick<string, any>,
  ...reset: string[]
): Record<string, any> | never => {
  if (typeof obj !== 'object') {
    return new Error('你传入的不是一个对象值')
  }
  const result: Record<string, any> = {}
  Object.keys(obj).forEach(key => {
    if (reset.includes(key)) {
      result[key] = obj[key]
    }
  })
  return result
}
/*
  example
  const obj = { a: 1, b: 2, c: 3 }
  const newObj = pick(obj, 'a', 'b')
  console.log(newObj) // { a: 1, b: 2 }
*/
